package support;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;


public class MasterFileReader {
  
    private BufferedReader brin = null;
	private boolean End = false;
	
	public boolean isEnd()
	{  return End;	}
	
	public String readLine() throws UnhandledBehaviourException
	{
		String arg="";
		try {
		if(brin.ready())
			arg=brin.readLine();
		if(!brin.ready())
			End=true;
		} catch (IOException e) {
			e.printStackTrace();
			throw new UnhandledBehaviourException(e.getMessage(), e);
		}
		return arg;
	}
	
	public MasterFileReader(String location) throws UnhandledBehaviourException
	{
	    File file = new File(location);
	    
	    try {
	      brin = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(file))));
	      End=false;
	    } catch (FileNotFoundException e) {
	      e.printStackTrace();
	      throw new UnhandledBehaviourException(e.getMessage(), e);
	    } catch (IOException e) {
	      e.printStackTrace();
	      throw new UnhandledBehaviourException(e.getMessage(), e);
	    }
	  }
	
	protected void finalize() throws Throwable {
	    try {
	        this.brin.close();        // close open files
	    } finally {
	        super.finalize();
	    }
	}
}
